package com.oig.sys.workflow.event;

import com.oig.sys.workflow.api.AuditCallService;
import com.oig.sys.workflow.dto.AuditCallMsgDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@Slf4j
public class AuditCallEventListener {

    private final AuditCallService auditCallService;


    public AuditCallEventListener(AuditCallService auditCallService){
        this.auditCallService = auditCallService;
    }

    @Async
    @Order
    @EventListener(AuditCallEvent.class)
    public void autoCall(AuditCallEvent event){
        log.debug("jpa审计触发自动化处理通知事件。");
        AuditCallMsgDto auditLogDto = (AuditCallMsgDto) event.getSource();
        auditCallService.rec(auditLogDto);    //可能会有网络等问题。调用失败，如何保证一定触发？或者补偿？
    }

}
